
#include "../../Command.h"

#include "../../User.h"
#include "../../NLogic/Static.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_REQ_DUNGEON_CREATE_SINGLE(User * pUser, ::Network::Packet *pPacket)
{
	/*
	 * /// 솔로 플레이
	CS_REQ_DUNGEON_CREATE_SINGLE	0x111b
	{

	}

	SC_REQ_DUNGEON_CREATE_SINGLE	0x111c
	{

	}
	 */

	STRESSLOG("CS_REQ_DUNGEON_CREATE_SINGLE");

	PREPARE_PACKET;

	NLogic::Space * pSpace = pUser->GetSpace();
	if (pSpace == NULL)
	{
		DEBUGLOG("CS_REQ_DUNGEON_CREATE_SINGLE pSpace == NULL");

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(ACK_UNKNOWN_ERROR);
		pAck->MakePacket(CMD_SC_REQ_DUNGEON_CREATE_SINGLE);
		pUser->Send(pAck);

		return;
	}



	if (false == pUser->EndBattle_afterEffect())
	{
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(ACK_BATTLE_AFTEREFFECT);
		pAck->MakePacket(CMD_SC_REQ_DUNGEON_CREATE_SINGLE);
		pUser->Send(pAck);
		STRESSLOG("CS_REQ_DUNGEON_CREATE_SINGLE ACK");

		return;
	}

	if (pUser->GetEnumState() != User::EnumState::__NONE__
			&& pUser->GetEnumState() != User::EnumState::ENTER_EVENT_DUNGEON)
	{
		DEBUGLOG("CS_REQ_DUNGEON_RANDOM_PARTY pUser->GetEnumState() != User::EnumState::__NONE__");

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(ACK_UNKNOWN_ERROR);
		pAck->MakePacket(CMD_SC_REQ_DUNGEON_CREATE_SINGLE);
		pUser->Send(pAck);

		return;
	}

	pSpace->LeaveUser(pUser);


	NLogic::Space::Data clsData;
	clsData._maxUser = 1;
	clsData._spaceType = NLogic::Space::SpaceType::SINGLE_DUNGEION;

	NLogic::Space * pSingleDungeon = NLogic::Static::Instance().GETSPACEPOOL()->NEW();
	pSingleDungeon->Open(pUser, clsData);


	pSingleDungeon->EnterUser(pUser);

	pUser->SetEnumState(User::EnumState::SINGLE_DUNGEON);

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pAck << static_cast<int16_t>(ACK_OK);
	pAck->MakePacket(CMD_SC_REQ_DUNGEON_CREATE_SINGLE);
	pUser->Send(pAck);
	STRESSLOG("CS_REQ_DUNGEON_CREATE_SINGLE ACK");
}

} /*NCommand*/ } /*ProjectZ*/
